package com.weifangfirecontrolformal.weifangfirecontrolformal.web.service.maintenancesystem.task;

import cn.hutool.json.JSONObject;
import com.weifangfirecontrolformal.weifangfirecontrolformal.common.base.BaseService;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.model.RespEntity;
import com.weifangfirecontrolformal.weifangfirecontrolformal.support.utils.requestutil.HttpRequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 统计分析
 */
@Slf4j
@Service
public class DataAnalysisService extends BaseService {

    /**
     * 大屏所需要的数据
     * @param jsonParam
     * @return
     */
    public RespEntity getBigScreenData(JSONObject jsonParam) {
        //处理支持form-data和json两种方式
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        return restJava(jsonParam,"dataAnalysis","getBigScreenData","task");
    }

    /**
     * 报表导出
     * @param
     * @return
     */
    public RespEntity getReport(JSONObject jsonParam) throws Exception {
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        return restJava(jsonParam, "task","getReport", "task");
    }
//    public ResponseEntity<byte[]> getReport(JSONObject jsonParam) throws Exception {
//        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
//        String filepath = (String) restJava(jsonParam, "task","getReport", "task").getData();
//        byte[] btImg = FileStrUtil.getImageFromNetByUrl(filepath);
//        HttpHeaders headers = new HttpHeaders();
//        // 下载显示的文件名，解决中文名称乱码问题
//        String downloadFielName = new String(filepath.substring(filepath.lastIndexOf("/")+1,filepath.length()).getBytes("UTF-8"), "iso-8859-1");
//        // 通知浏览器以attachment（下载方式）打开文件
//        headers.setContentDispositionFormData("attachment", downloadFielName);
//        // application/octet-stream ： 二进制流数据（最常见的文件下载）。
//        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//        return new ResponseEntity<byte[]>(btImg, headers, HttpStatus.CREATED);
//    }
}
